<!DOCTYPE html>

<html>

<head>

<title>setInterval()方法的应用</title>

</head>

<body>

<canvas id="myCanvas" width="400" height="400" style="border:3px double #996633;">

</canvas>

<script type="text/javascript">

   var canvas = document.getElementById('myCanvas');

   var ctx = canvas.getContext('2d');

   var i=0;

   function move()

   {

       ctx.fillStyle = 'red';

       ctx.fillRect(i,i,50,50);

       i++;

       if (i==350)

       {

           i=0;

           ctx.clearRect(0,0,400,400);

       }

   }

   setInterval("move()",10);

</script>

</body>

</html>